﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Castle.ActiveRecord;

namespace TVN.ShopMan.ApplicationInterface.Helpers
{
    using TVN.Common.Interfaces;
    using TVN.ShopMan.ActiveModels;

    public class AppHelper<T> where T : ActiveRecordBase<T>
    {
        public static bool IsExists(string propertyName, string propertyValue, bool isCreating)
        {
            bool result = false;
            IRepository<T> repository = Program.Container.Resolve<IRepository<T>>();

            IDictionary propertyNameValues = new Dictionary<string, string>();
            propertyNameValues.Add(propertyName, propertyValue);

            IList<T> items = repository.FindBy(propertyNameValues);
            if (items != null)
            {
                if (isCreating)
                {
                    result = (items.Count >= 1);
                }
                else
                {
                    result = (items.Count >= 2);
                }
            }

            return result;
        }
    }
}
